﻿package com.wandian.view.mediator
{
	import com.wandian.controller.CLZNoticeName;
	import com.wandian.data.GameData;
	import com.wandian.util.CLZButton;

	import flash.events.MouseEvent;

	import org.puremvc.as3.interfaces.*;
	import org.puremvc.as3.patterns.mediator.*;

	/**
	 * 游戏内顶层遮罩加载显示
	 * @author long 2012-10-22
	 */
	public class MaskGameMediator extends Mediator
	{
		private var _global:GameData;
		public static const NAME:String="MaskGameMediator";

		/**
		 *  游戏内顶层显示
		 * @param viewComponent
		 */
		public function MaskGameMediator(viewComponent:Object=null)
		{
			this._global=GameData.getInstance();
			super(NAME, viewComponent);
			return;
		} 

		override public function onRegister():void
		{
			CLZButton.setButton(this.mcMask.return_btn, GameData.tip["RETURN_ROOM_LIST_BTN"]); //返回大厅
			this.sendNotification(CLZNoticeName.REGISTER, GameData._objRoom);
			this.mcMask.return_btn.addEventListener(MouseEvent.CLICK, this.onReturnRoomHandler);
			return;
		} 

		override public function listNotificationInterests():Array
		{
			return [CLZNoticeName.REGISTER, CLZNoticeName.RESPONSE_ROOM_INFO_SUCC];
		} 

		override public function handleNotification(notification:INotification):void
		{
			switch (notification.getName())
			{
				case CLZNoticeName.REGISTER:
				{
					trace("[MaskGameMediator]收到REGISTER,隐藏顶部");
					this.sendNotification(CLZNoticeName.HIDE_TOP); //隐藏顶部
					this.showMaskTip(GameData.tip["REQUESTROOMPLAYER"]); //正在获取房间信息……
					break;
				}
				case CLZNoticeName.RESPONSE_ROOM_INFO_SUCC:
				{
					trace("[MaskGameMediator.RESPONSE_ROOM_INFO_SUCC]显示顶部");
					this.showMaskTip("", false); //隐藏遮罩
					this.sendNotification(CLZNoticeName.SHOW_TOP); //显示顶部
					break;
				}
				default:
				{
					break;
				}
			}
			return;
		} 

		private function showMaskTip(htmlTxt:String, boolvisible:Boolean=true):void
		{
			if (!boolvisible)
			{
				this.mcMask.visible=false;
				GameData.stopMcAllChild(this.mcMask.swfIcon_mc);
			}
			else
			{
				this.mcMask.visible=true;
				GameData.playMcAllChild(this.mcMask.swfIcon_mc);
			}
			this.mcMask.txt.htmlText=htmlTxt;
			this.mcMask.showGameTip();
			return;
		} 

		private function onReturnRoomHandler(event:MouseEvent):void
		{
			this.sendNotification(CLZNoticeName.OUT_GAME_ROOM_RSP, {userid: this._global.userInfo.userVo.userid});
			return;
		} 

		private function get mcMask():Object
		{
			return viewComponent;
		} 

	}
}
